
--加载badboy库
local bb = require("badboy");
--加载utils模块
bb.loadutilslib();

Middle = "Middle";
Bottom = "Bottom";

GreenColor = "GreenColor";
YellowColor = "YellowColor";

MiddleRect = {0,935,1243 - 250,1295};
BottomRect = {0 + 250, 1409, 1243, 1758};

throwCount = 0;

function main ()
  
  require("find");
  require("operation");
  
  --home键在下
  init("", 0);
  
  
  while true do
    
    local position = bestPositionForThrow();
    if position ~= nil then
      throwBasketBall(position.color, position.area, position.x, position.y);
      throwCount = throwCount + 1;
      --sysLog("投球次数是"..throwCount);
    else
      
      mSleep(30);
      
    end
    
    --判断是否是再玩一次页面
    local playAgainBtnX, playAgainBtnY = playAgainButtonPosition();
    if playAgainBtnX > -1 then
      tap(playAgainBtnX, playAgainBtnY);
      mSleep(1000);
      
    end
    
    --判断是否是开始游戏页面
    local beginGameBtnX, beginGameBtnY = beginGameButtonPosition();
    if beginGameBtnX > -1 then
      tap(beginGameBtnX, beginGameBtnY);
      mSleep(1000);
			
			--初始化投球次数
			throwCount = 0;
			
			--把第一个球扔掉
			throwFirstBall();
			
    end
    
  end
  
end


main();